﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace csharpcore7_ch14_ConcurrencyAndAsynchrony
{
    class chapt14_3_1_1WaitMethod
    {
        static void  _Main()
        {
            Task task = Task.Run(()=>
            {
                Thread.Sleep(2000);
                Console.WriteLine("Foo");
            });
            Console.WriteLine(task.IsCompleted);//False
            task.Wait();    //Blocks until task is complete          
        }

        static void __Main(string[] args)
        {
            for (int i = 2, j = 1; i < 10 && j <= 1000; i++)//输出21亿内的所有质数，j控制只输出1000个。
　           {
                if (st(i))
                {
                    Console.WriteLine("{0,-10}{1}", j, i);
                    j++;
                }
            }
        }
        static bool st(int n)//判断一个数n是否为质数
　       {
            int m = (int)Math.Sqrt(n);
            for (int i = 2; i <= m; i++)
            {
                if (n % i == 0 && i != n)
                    return false;
            }
            return true;
        }
    }
}

